import { defHttp } from '@/utils/http/axios';
import {
  ServerInfo,
  ServerParams,
  ServerListGetResultModel,
  ServerAddReq,
  ServerEditReq,
  ServerDelReq,
} from './model/serverModel';

enum Api {
  List = '/api/admin/v1/servers/list',
  Create = '/api/admin/v1/servers/add',
  Update = '/api/admin/v1/servers/edit',
  Delete = '/api/admin/v1/servers/del',
  Info = '/api/admin/v1/servers/info',
}

/**
 * @description: 获取服务器列表
 */
export const getServerList = (params: ServerParams) =>
  defHttp.get<ServerListGetResultModel>({
    url: Api.List,
    params,
    headers: { 'Content-Type': 'multipart/form-data' },
  });

/**
 * @description: 创建服务器
 */
export const createServer = (params: ServerAddReq) =>
  defHttp.post<{ id: number }>({ url: Api.Create, params });

/**
 * @description: 更新服务器
 */
export const updateServer = (params: ServerEditReq) =>
  defHttp.put<void>({ url: Api.Update, params });

/**
 * @description: 删除服务器
 */
export const deleteServer = (params: ServerDelReq) =>
  defHttp.delete<void>({ url: Api.Delete, params });

/**
 * @description: 获取服务器详情
 */
export const getServerInfo = (id: number) =>
  defHttp.get<ServerInfo>({ url: Api.Info, params: { id } });
